<template>
	<view>
		<view v-for="(item,index) in itemList" :key="index">
			<view @click="itemClick(item)" class="item flex-row-space-between">
				<view class="title">
					{{item.name}}
				</view>
				<view class="flex-row-flex-end">
					<view v-if="item.name=='实名认证'" class="">
						<text v-if='Number(userInfo.is_auth)==1'>已认证</text>
						<text v-else style="color: red;">未认证</text>
					</view>
					<u-icon name="arrow-right" size="16" color="#666666"></u-icon>
				</view>

			</view>

		</view>
	</view>
</template>

<script>
	import {
		getUserInfo,
		setUserInfo,
	} from "@/api/user";
	import Cache from "@/utils/cache"

	import {
		BACK_URL,
		CONFIG,
		USER_INFO,
		TOKEN
	} from '@/config/cachekey'
	export default {
		components: {},
		computed: {

		},
		data() {
			return {
				userInfo: {},
				itemList: [{
						name: '实名认证',
						url: '/pages/user/realName',
						icon: "/static/my/3.png"
					},
					{
						name: '平台协议',
						url: '/bundle/pages/server_explan/server_explan?type=0',
						icon: "/static/my/4.png"
					},
					{
						name: '退出登录',
						url: '/pages/user/feedback',
						icon: "/static/my/5.png"
					},
					{
						name: '添加银行卡',
						url: '/pages/user/addBankCard',
						icon: "/static/my/5.png"
					}
				],

			}
		},
		onShow() {
			this.$getUserInfo()
		},
		onLoad(e) {
			// #ifdef MP-WEIXIN 
			this.itemList = [
				{
					name: '实名认证',
					url: '/pages/user/realName',
					icon: "/static/my/3.png"
				},
				{
					name: '平台协议',
					url: '/bundle/pages/server_explan/server_explan?type=0',
					icon: "/static/my/4.png"
				},
				{
					name: '退出登录',
					url: '/pages/user/feedback',
					icon: "/static/my/5.png"
				},
				{
					name: '添加银行卡',
					url: '/pages/user/addBankCard',
					icon: "/static/my/5.png"
				}
			]
			//#endif
		},
		//下拉刷新
		onPullDownRefresh() {


		},
		//加载更多
		onReachBottom() {

		},

		methods: {
			$getUserInfo() {
				getUserInfo().then(res => {
					if (res.code == 1) {
						this.userInfo = res.data;

					}
				});
			},
			login1() {
				// USER_INFO: 'USER_INFO',
				// TOKEN: 'TOKEN',
				// BACK_URL: 'BACK_URL',
				// CONFIG: 'CONFIG'
				this.$store.commit("LOGOUT");
				Cache.remove(USER_INFO)
				Cache.remove(TOKEN)
				Cache.remove(BACK_URL)
				Cache.remove(CONFIG)
				uni.navigateTo({
					url: "/pages/login/login"
				})
			},
			login() {
				var that = this
				uni.showModal({
					title: '退出登录',
					content: '您确认退出登录吗？',
					success: function(res) {
						if (res.confirm) {
							that.login1()
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			itemClick(item) {
				if (item.name == '实名认证' && Number(this.userInfo.is_auth) == 1) {
					this.showToast('已认证')
					return
				}
				if (item.name == '退出登录') {
					this.login()
					return
				}
				uni.navigateTo({
					url: item.url
				})
			},
			showToast(title) {
				uni.showToast({
					title: title,
					icon: 'none'
				})
			},
			toUrl(url) {
				uni.navigateTo({
					url: url
				})
			},
		}
	}
</script>

<style lang="scss">
	.item {
		padding: 0 20rpx;
		margin-left: 5%;
		width: 90%;
		margin-top: 20rpx;
		// margin: 20rpx;
		height: 105rpx;
		background: #FFFFFF;
		border-radius: 11rpx 11rpx 11rpx 11rpx;
		opacity: 1;
	}

	.title {
		font-size: 27rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 500;
		color: #000000;
	}
</style>